home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 October: Mac OS SDK / Dev.CD Oct 97 SDK1.toast / Development Kits (Disc 1) / AppleScript / Development Tools / Sample Code / 7Edit 3.1 / Sources / SVEditFile.c < prev    next >
Encoding:
Text File  |  1995-11-20  |  16.6 KB  |  740 lines  |  [TEXT/CWIE]

  1. // SVEditFile.c
  2. //
  3. // 7Edit 3.1d1. Original version by Jon Lansdell and Nigel Humphreys.
  4. // 3.1 updates by Greg Sutton.
  5. // ©Apple Computer Inc 1995, all rights reserved.
  6.     
  7. #include <Errors.h>
  8. #include <Resources.h>
  9. #include <Desk.h>
  10. #include <PLStringFuncs.h>
  11. #include <AppleEvents.h>
  12. #include <AERegistry.h>
  13. #include <StandardFile.h>
  14. #include "SVEditFile.h"
  15. #include "Offscreen.h"
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22. /**-----------------------------------------------------------------------
  23.         Name:             FileError
  24.         Purpose:        Puts up an error alert.
  25.     -----------------------------------------------------------------------**/
  26.  
  27.     
  28. #pragma segment File
  29.  
  30. pascal void FileError(Str255 s, Str255 f)
  31.   {
  32.     short    alertResult;
  33.  
  34.     SetCursor(&qd.arrow);
  35.         ParamText(s, f, (unsigned char *)"", (unsigned char *)"");
  36.     alertResult = Alert(ErrorAlert, nil);
  37.     }
  38.  
  39. /**-----------------------------------------------------------------------
  40.         Name:             DoClose
  41.         Purpose:        Closes a window.
  42.     -----------------------------------------------------------------------**/
  43.  
  44. #pragma segment File
  45.  
  46. pascal OSErr DoClose(WindowPtr aWindow,Boolean canInteract,DescType dialogAnswer)
  47. {
  48.     DPtr    aDocument;
  49.     short   alertResult;
  50.     OSErr   myErr;
  51.                         
  52.     myErr = noErr;
  53.         
  54.     if (gWCount>0)
  55.     {
  56.         aDocument = DPtrFromWindowPtr(aWindow);
  57.             
  58.         if (aDocument->dirty)
  59.             if (canInteract && (dialogAnswer==kAEAsk))
  60.             {
  61.                 alertResult = DoFileDialog ( kSaveDontsaveDialog, aWindow );
  62.                 switch ( alertResult )
  63.                 {
  64.                     case kStdOkItemIndex:
  65.                         if (aDocument->everSaved == false)
  66.                         {
  67.                             myErr = GetFileNameToSaveAs(aDocument);
  68.                             if (myErr == noErr)
  69.                                 myErr = DoSave(aDocument, aDocument->theFSSpec);
  70.                                                                                                     }
  71.                         else
  72.                             myErr = SaveUsingTemp(aDocument);
  73.                     break;
  74.                                                                 
  75.                     case kStdCancelItemIndex:
  76.                         return(userCanceledErr);
  77.                     break;
  78.                     
  79.                     case kDontSaveItemIndex:
  80.                         aDocument->dirty = false;
  81.                     break;
  82.                 }
  83.             }
  84.             else
  85.             {
  86.                 if (dialogAnswer==kAEYes)
  87.                     if (aDocument->everSaved == false)
  88.                     {
  89.                         if (canInteract)
  90.                         {
  91.                             myErr = GetFileNameToSaveAs(aDocument);
  92.                             if (myErr==noErr)
  93.                                 myErr = DoSave(aDocument, aDocument->theFSSpec);
  94.                         }
  95.                         else    
  96.                             return(errAENoUserInteraction);
  97.                     }
  98.                     else
  99.                         myErr = SaveUsingTemp(aDocument);
  100.                 else
  101.                     myErr = noErr; /* Don't save */
  102.             }
  103.                 
  104.             if (myErr==noErr)
  105.             {
  106.                 CloseMyWindow(aWindow);
  107.             }
  108.     }
  109.     else
  110.         myErr = errAEIllegalIndex;
  111.             
  112.     return(myErr);
  113. }
  114.  
  115.  
  116.  
  117. //
  118. // This is called to display the "save before closing" and "revert" dialogs.
  119. //
  120. short DoFileDialog ( short theDlogID, WindowRef theWindow )
  121. {
  122.     short        theItem;
  123.     DialogRef    theDialog;
  124.     WindowRef    dialogWindow;
  125.     DPtr        theDocument;
  126.     Str255        theTitle, theReason;
  127.     
  128.     
  129.     theDocument = DPtrFromWindowPtr ( theWindow );
  130.     
  131.     theDialog = GetNewDialog ( theDlogID, nil, (WindowRef) -1 );
  132.     dialogWindow = GetDialogWindow ( theDialog );
  133.     SetPortWindowPort ( dialogWindow );
  134.     
  135.     
  136.     if ( theDocument->everSaved == false )
  137.         GetWTitle ( theWindow, theTitle );         // Pick it up as a script may have changed it
  138.     else
  139.         PLstrcpy ( theTitle, theDocument->theFileName );
  140.     
  141.     if ( gQuitting )
  142.         GetIndString ( theReason, kMiscStrings, kQuittingIndex );
  143.     else
  144.         GetIndString ( theReason, kMiscStrings, kClosingindex );
  145.     
  146.     SetCursor ( &qd.arrow );
  147.     ParamText ( theTitle, theReason, nil, nil );
  148.     ShowWindow ( dialogWindow );
  149.     SelectWindow ( dialogWindow );
  150.     
  151.     SetDialogDefaultItem ( theDialog, kStdOkItemIndex );
  152.     SetDialogCancelItem ( theDialog, kStdCancelItemIndex );
  153.     
  154.     
  155.     // As long as the only enabled items are the dimissers, 
  156.     // there is no need to call ModalDialog within a loop.
  157.     ModalDialog ( nil, &theItem );
  158.     DisposeDialog ( theDialog );
  159.     
  160.     return theItem;
  161. }        
  162.  
  163.  
  164.  
  165. #pragma segment File
  166.  
  167. //  DoQuit
  168. //  saveOpt - one of kAEAsk,kAEYes,kAENo
  169. //  if kAEYes or kAEAsk then AEInteactWithUser should have been called
  170. //  before DoQuit. Assumes that it can interact if it needs to.
  171.  
  172. pascal void DoQuit ( DescType saveOpt )
  173. {
  174.     WindowPtr    aWindow;
  175.     WindowPtr    nextWindow;
  176.     WindowPeek   nextWPeek;
  177.     short        theKind;
  178.     OSErr        check;
  179.     
  180.     aWindow = FrontWindow();
  181.     
  182.     gQuitting = true;
  183.     while ( aWindow )
  184.     {
  185.         nextWPeek  = ((WindowPeek)aWindow)->nextWindow;
  186.         nextWindow = &nextWPeek->port;
  187.         if (Ours(aWindow))
  188.         {
  189.             check = DoClose(aWindow, true, saveOpt);
  190.             if ( check != noErr )
  191.             {
  192.                 gQuitting = false;
  193.                 return;
  194.             }
  195.         }
  196.         else
  197.         {
  198.             theKind = ((WindowPeek)aWindow)->windowKind;
  199.             if (theKind < 0)
  200.                 CloseDeskAcc(theKind);
  201.         }
  202.         aWindow = nextWindow;
  203.     }
  204.     
  205.     return;
  206.     
  207. } // DoQuit
  208.  
  209.  
  210.  
  211. pascal OSErr GetFile(FSSpec *theFSSpec)
  212.   {
  213.     SFTypeList         myTypes;
  214.     StandardFileReply  reply;
  215.  
  216.         myTypes[0] = 'TEXT';
  217.  
  218.         StandardGetFile(nil, 1, myTypes, &reply);
  219.  
  220.         if (reply.sfGood)
  221.             {
  222.                 *theFSSpec = reply.sfFile;
  223.                 return(noErr);
  224.             }
  225.         else
  226.             return(userCanceledErr);
  227.  }
  228.  
  229. #pragma segment File
  230.  
  231.  
  232. pascal OSErr DoCreate(FSSpec theSpec)
  233.   {
  234.       OSErr err;
  235.  
  236.       err = FSpCreate(&theSpec, SVEditAppSig, 'TEXT', smSystemScript);
  237.  
  238.       if (err != noErr)
  239.               ShowError((unsigned char *)"\pDoCreate", err);
  240.                 
  241.             return(err);
  242.     }
  243.  
  244. #pragma segment File
  245.  
  246.  
  247. pascal OSErr WriteFile(DPtr theDocument, short refNum, FSSpec theFSSpec)
  248.   {
  249.     short        resFile;
  250.     long         length;
  251.     HHandle      theHHandle;
  252.     StScrpHandle theSHandle;
  253.     OSErr        err;
  254.     StringHandle theAppName;
  255.     short        oldSelStart;
  256.     short        oldSelEnd;
  257.     Handle       thePHandle;
  258.     Handle       myText;
  259.     Handle       thePGXHandle;
  260.     
  261.     tWindowOffscreen*    theOffscreen = nil;
  262.  
  263.                 
  264. /*        WriteFile := 1; */
  265.  
  266.     /*first write out the text to the data fork*/
  267.         
  268.         length = (*(theDocument->theText))->teLength;
  269.         
  270.         myText = (*(theDocument->theText))->hText;
  271.         
  272.     HLock(myText);
  273.     
  274.         err = FSWrite(refNum, &length, *myText);
  275.         if (err)
  276.           return(err);
  277.             
  278.     HUnlock(myText);
  279.  
  280.         /*we are writing to a temporary file, so we need to create the resource file*/
  281.         /*before writing out the resources*/
  282.         /*now open the resource file*/
  283.         
  284.         HCreateResFile(theFSSpec.vRefNum, theFSSpec.parID, theFSSpec.name);
  285.         err = ResError();
  286.         if (err)
  287.           {
  288.                 ShowError((unsigned char *)"\pHCreateResFile", err);
  289.                 return(err);
  290.             }
  291.  
  292.     resFile = HOpenResFile(theFSSpec.vRefNum, theFSSpec.parID, theFSSpec.name, fsWrPerm);
  293.     err = ResError();
  294.  
  295.     if (err)
  296.           {
  297.                 ShowError((unsigned char *)"\pHOpenResFile", err);
  298.                 return(err);
  299.             }
  300.  
  301.      /*write out our 'TFSF' resource to file*/
  302.      
  303.      //    Draw everything into offscreen pixmap.
  304.     theOffscreen = DrawOffscreen ( theDocument->theWindow );
  305.     if ( theOffscreen  )
  306.         (*theDocument->theText)->inPort = (GrafPtr) theOffscreen->offscreenWorld;
  307.     
  308.     
  309.     oldSelStart = (*(theDocument->theText))->selStart;
  310.     oldSelEnd   = (*(theDocument->theText))->selEnd;
  311.     TESetSelect(0,32000, theDocument->theText);
  312.     
  313.     theSHandle = TEGetStyleScrapHandle(theDocument->theText);
  314.     
  315.     TESetSelect(oldSelStart,oldSelEnd, theDocument->theText);
  316.     
  317.     
  318.     if ( theOffscreen )
  319.     {
  320.         // If it wasn't for the caret, we wouldn't need to draw this
  321.         theOffscreen = DrawOnscreen ( theOffscreen );
  322.         (*theDocument->theText)->inPort = theDocument->theWindow;
  323.     }
  324.     
  325.     AddResource((Handle)theSHandle, 'TFSF', 255, (unsigned char *)"\pStyle Info");
  326.     err = ResError();
  327.     if (err)
  328.           {
  329.                 ShowError((unsigned char *)"\pAddResource- TFSF", err);
  330.                 return(err);
  331.             }
  332.                     
  333. // write out the printer info
  334.                 
  335.     // First the QD info
  336.                 
  337.         if (theDocument->thePrintSetup)
  338.             {
  339.                 thePHandle = (Handle)theDocument->thePrintSetup;
  340.                 err = HandToHand(&thePHandle);
  341.                 
  342.                 AddResource(thePHandle, 'TFSP', 255, (unsigned char *)"\pPrinter Info");
  343.                 err = ResError();
  344.                 if (err)
  345.                     {
  346.                         ShowError((unsigned char *)"\pAddResource- TFSP", err);
  347.                         return(err);
  348.                     }
  349.             }
  350.                 
  351.     // Next the QD QX info
  352.         if (   (gGXIsPresent)
  353.                 && (theDocument->documentJob))
  354.             {
  355.                 thePGXHandle = NewHandle(0);
  356.                 GXFlattenJobToHdl(theDocument->documentJob, thePGXHandle);
  357.  
  358.                 AddResource(thePGXHandle, 'TFGX', 255, (unsigned char *)"\pGX Printer Info");
  359.                 err = ResError();
  360.                 if (err)
  361.                 {
  362.                     ShowError((unsigned char *)"\pAddResource- TFGX", err);
  363.                     return(err);
  364.                 }
  365.             }
  366.                 
  367.         theHHandle = (HHandle)NewHandle(sizeof(HeaderRec));
  368.     HLock((Handle)theHHandle);
  369.  
  370.         GetFontName(theDocument->theFont, (unsigned char *)&(*theHHandle)->theFont);
  371.         (*theHHandle)->theSize     = theDocument->theSize;
  372.         (*theHHandle)->theStyle    = theDocument->theStyle;
  373.         (*theHHandle)->lastID      = theDocument->lastID;
  374.  
  375.         HUnlock((Handle)theHHandle);
  376.  
  377.         AddResource((Handle)theHHandle, 'TFSS', 255, (unsigned char *)"\pHeader Info");
  378.  
  379.         err = ResError();
  380.         if (err)
  381.             {
  382.                 ShowError((unsigned char *)"\pAddResource- TFSS", err);
  383.                 return(err);
  384.             }
  385.  
  386.         /*if we have any sections, write out the records and resources*/
  387.         
  388.         /*Now put an AppName in for Finder in 7.0*/
  389.  
  390.         theAppName = (StringHandle)NewHandle(6);
  391.         PLstrcpy(*theAppName,(unsigned char *)"\p7Edit");
  392.         
  393.         AddResource((Handle)theAppName, 'STR ', - 16396, (unsigned char *)"\pFinder App Info");
  394.  
  395.         err = ResError();
  396.  
  397.         if (err)
  398.             {
  399.                 ShowError((unsigned char *)"\pAppName", err);
  400.                 return(err);
  401.             }
  402.  
  403.         CloseResFile(resFile);
  404.  
  405.         return(noErr);
  406.     } /* WriteFile */
  407.  
  408. #pragma segment File
  409.  
  410. pascal OSErr ReadFile(DPtr theDocument, short  refNum, Str255 fn)
  411.  {
  412.         long            theSize;
  413.         short           resFile;
  414.         OSErr           err;
  415.         HHandle         aHandle;
  416.         Handle          gHandle;
  417.         Handle          hGXJobData;
  418.         Boolean         gotQDPrintRec;
  419.         
  420.         gotQDPrintRec = false;
  421.  
  422.         err = GetEOF(refNum, &theSize);
  423.                 if (err)
  424.           return(err);
  425.  
  426.         /*we're only using TE, so check that there is not more than 32K worth of text*/
  427.                 
  428.         if (theSize > 32000)
  429.           return(1);
  430.  
  431.         gHandle = NewHandle(theSize);
  432.         HLock(gHandle);
  433.                 err = FSRead(refNum, &theSize, *gHandle);
  434.                 
  435.         if (err)
  436.           {
  437.             HUnlock(gHandle);
  438.                         return(err);
  439.           }
  440.                                 
  441.                 resFile = HOpenResFile(theDocument->theFSSpec.vRefNum, 
  442.                                                              theDocument->theFSSpec.parID,
  443.                                                              fn,
  444.                                                              fsWrPerm);
  445.                 if (resFile == -1)
  446.                     err = fnfErr;
  447.                     
  448.                 if (err==noErr)
  449.                     {
  450.                         aHandle = nil;
  451.         
  452.                         if (Count1Resources('TFSS'))
  453.                             aHandle = (HHandle)Get1Resource('TFSS', 255);
  454.                         /*
  455.                             New Format Info
  456.                         */
  457.                         
  458.                         aHandle = nil;
  459.                         
  460.                         if (Count1Resources('TFSF'))
  461.                             aHandle = (HHandle)Get1Resource('TFSF', 255);
  462.                             
  463.                         HLock(gHandle);
  464.                         TEStylInsert(    *gHandle,
  465.                                                     GetHandleSize(gHandle),
  466.                                                     (StScrpHandle)aHandle,
  467.                                                     theDocument->theText);
  468.                                         
  469.                         HUnlock(gHandle);
  470.                         
  471.                         /*
  472.                             If there is a print record saved, ditch the old one
  473.                             created by new document and fill this one in
  474.                         */
  475.                         if (Count1Resources('TFSP'))
  476.                         {
  477.                             if (theDocument->thePrintSetup)
  478.                                 DisposHandle((Handle)theDocument->thePrintSetup);
  479.                             
  480.                             theDocument->thePrintSetup = (THPrint)Get1Resource('TFSP', 255);
  481.                               err = HandToHand((Handle *)&theDocument->thePrintSetup);
  482.                             
  483.                             gotQDPrintRec = true;
  484.                             if (! gGXIsPresent)
  485.                                 PrValidate(theDocument->thePrintSetup);
  486.                         }
  487.  
  488.                         if (gGXIsPresent)
  489.                             if (Count1Resources('TFGX'))
  490.                                 {
  491.                                     if (theDocument->documentJob)
  492.                                         {
  493.                     //                        GXDisposeJob(theDocument->documentJob);
  494.                     //                        theDocument->documentJob = nil;
  495.                                         }
  496.  
  497.                                     hGXJobData = Get1Resource('TFGX', 255);
  498.  
  499.                                     if (hGXJobData)
  500.                                         {
  501.                                             GXUnflattenJobFromHdl(theDocument->documentJob, hGXJobData);
  502.                                             err = GXGetJobError(theDocument->documentJob);
  503.                                             ReleaseResource(hGXJobData);
  504.                                         }
  505.                                 }
  506.                             else
  507.                             {
  508.                                 if (gotQDPrintRec)
  509.                                     GXConvertPrintRecord(theDocument->documentJob, theDocument->thePrintSetup);
  510.                             }
  511.  
  512.                         CloseResFile(resFile);
  513.         
  514.                         err = ResError();
  515.                         if (err)
  516.                             {
  517.                                 ShowError((unsigned char *)"\pread file- CloseResFile", err);
  518.                                 return(err);
  519.                             }
  520.           }
  521.                 else
  522.                     TESetText(*gHandle, 
  523.                               GetHandleSize(gHandle), 
  524.                                         theDocument->theText);
  525.                     
  526.                 if (gHandle)
  527.                     DisposHandle(gHandle);
  528.                     
  529.                 if (err==fnfErr)
  530.                     err = noErr;
  531.  
  532.         return(err);
  533.         } /* ReadFile */
  534.  
  535. /** -----------------------------------------------------------------------
  536.         Name:             GetFileContents
  537.         Purpose:        Opens the document specified by theFSSpec and puts
  538.                                 the contents into theDocument.
  539.      -----------------------------------------------------------------------**/
  540.  
  541.     
  542. #pragma segment File
  543.  
  544. pascal OSErr GetFileContents(FSSpec theFSSpec, DPtr theDocument)
  545.   {
  546.      OSErr            err;
  547.      short            theRefNum;
  548.  
  549.             /*this can be called from two places- on an OpenDoc AppleEvent*/
  550.             /*and by the user just selecting Open from the File Menu*/
  551.             /*assume that the CFS is correct when the routine is called*/
  552.  
  553.             err = FSpOpenDF(&theFSSpec,
  554.                                           fsRdWrPerm,
  555.                                           &theRefNum);
  556.             if (err)
  557.                 {
  558.                     ShowError((unsigned char *)"\pFSpOpenDF", err);
  559.                     return(err);
  560.                 }
  561.             else
  562.                 {
  563.                     err = ReadFile(theDocument, theRefNum, theFSSpec.name);
  564.                     if (err)
  565.                         {
  566.                             ShowError((unsigned char *)"\pReadFile", err);
  567.                             return(err);
  568.                         }
  569.                     err=FSClose(theRefNum);
  570.                     if (err)
  571.                         {
  572.                             ShowError((unsigned char *)"\pFSClose", err);
  573.                             return(err);
  574.                         }
  575.                     return(noErr);
  576.                 }
  577.         }
  578.  
  579.     
  580. #pragma segment File
  581.  
  582. pascal OSErr SaveUsingTemp(DPtr theDocument)
  583.   {
  584.     Str255           tempName;
  585.     OSErr            err;
  586.         FSSpec                tempFSSpec;
  587.  
  588.         /*save the file to disk using a temporary file*/
  589.         /*this is the recommended way of doing things*/
  590.         /*first write out the file to disk using a temporary filename*/
  591.         /*if it is sucessfully written, exchange the temporary file with the last one saved*/
  592.     /*then delete the temporary file- so if anything goes wrong, the original version is still there*/
  593.         /*first generate the temporary filename*/
  594.  
  595.         GetTempFileName(theDocument, tempName);
  596.         /*create this file on disk*/
  597.  
  598.         tempFSSpec      = theDocument->theFSSpec;
  599.         PLstrcpy(tempFSSpec.name,tempName);
  600.             
  601.         err = DoCreate(tempFSSpec);    
  602.  
  603.         /*now save the file as normal*/
  604.         
  605.         if (err==noErr)
  606.             err = DoSave(theDocument, tempFSSpec);
  607.         
  608.         if (err == noErr)
  609.             err = FSpExchangeFiles(&tempFSSpec, &theDocument->theFSSpec);
  610.  
  611.         /*we've exchanged the files, now delete the temporary one*/
  612.         
  613.         if (err==noErr)
  614.           err = FSpDelete(&tempFSSpec);
  615.  
  616.         return(err);
  617.     }
  618.  
  619.     
  620. #pragma segment File
  621.  
  622. /*
  623.     Fills in the document record with the user chosen destination
  624. */
  625.  
  626. pascal OSErr GetFileNameToSaveAs(DPtr theDocument)
  627.     {            
  628.     StandardFileReply   reply;
  629.     OSErr               err;
  630.         Str255              suggestName;
  631.  
  632.         GetWTitle(theDocument->theWindow, suggestName);
  633.  
  634.         StandardPutFile((unsigned char *)"\pSave Document As:", suggestName, &reply);
  635.  
  636.     if (reply.sfGood)
  637.             {                
  638.                 err = FSpDelete(&reply.sfFile);
  639.                 
  640.                 if (!((err==noErr) || (err==fnfErr)))
  641.                     return(err);
  642.                 else
  643.                     err = noErr;
  644.                     
  645.                 theDocument->theFSSpec = reply.sfFile;
  646.                 PLstrcpy(theDocument->theFileName, reply.sfFile.name);
  647.             }
  648.         else
  649.             err = userCanceledErr;
  650.         
  651.         return(err);
  652.  } /* GetFileNameToSaveAs */
  653.  
  654.     
  655. #pragma segment File
  656.  
  657. pascal OSErr DoSave(DPtr   theDocument, FSSpec theFSSpec)
  658.   {
  659.     short      refNum;
  660.     OSErr      fileErr;
  661.  
  662.         fileErr = FSpOpenDF(&theFSSpec, fsRdWrPerm, &refNum);
  663.         
  664.         if (fileErr == fnfErr)
  665.             {
  666.               fileErr = DoCreate(theFSSpec);
  667.                 
  668.                 if (fileErr)
  669.                     return(fileErr);
  670.                     
  671.                 fileErr = FSpOpenDF(&theFSSpec, fsRdWrPerm, &refNum);
  672.             }
  673.  
  674.         if (fileErr == noErr)
  675.             {
  676.               fileErr = WriteFile(theDocument, refNum, theFSSpec);
  677.                 
  678.                 if (fileErr==noErr)
  679.                     theDocument->dirty = false;
  680.                     
  681.                 fileErr = FSClose(refNum);
  682.             }
  683.         else
  684.             FileError((unsigned char *)"\perror opening file ", theFSSpec.name);
  685.         
  686.         return(fileErr);
  687.     }
  688.  
  689.     
  690. #pragma segment File
  691.  
  692. pascal OSErr OpenOld(FSSpec aFSSpec)
  693.     {        
  694.       DPtr  theDocument;
  695.         OSErr fileErr;
  696.  
  697.         theDocument = NewDocument(true, (WindowPtr)-1L);
  698.         
  699.         SetWTitle(theDocument->theWindow, aFSSpec.name);
  700.         
  701.         SetPort(theDocument->theWindow);
  702.         
  703.         theDocument->theFSSpec   = aFSSpec;
  704.         
  705.         PLstrcpy(theDocument->theFileName,aFSSpec.name);
  706.         
  707.         theDocument->dirty       = false;
  708.         theDocument->everSaved   = true;
  709.  
  710.     fileErr = GetFileContents(aFSSpec, theDocument);
  711.         
  712.         if (fileErr == noErr)
  713.             {
  714.                 ResizeWindow(theDocument);
  715.                 ShowWindow(theDocument->theWindow);
  716.             }
  717.         else
  718.             FileError((unsigned char *)"\pError Opening ", aFSSpec.name);
  719.                     
  720.         return(fileErr);
  721.     } /* OpenOld */
  722.  
  723.     
  724. #pragma segment File
  725.  
  726. pascal OSErr OpenUsingAlias(AliasHandle theAliasH)
  727.   {
  728.     OSErr    err;
  729.     FSSpec   aFSSpec;
  730.     Boolean  dummy;
  731.  
  732.         err = ResolveAlias(nil, theAliasH, &aFSSpec, &dummy);
  733.         
  734.         if (err == noErr)
  735.             err = OpenOld(aFSSpec);
  736.                     
  737.         return(err);
  738.     }
  739.  
  740.